package com.hmdp.config;

import com.hmdp.interceptor.ExpireInterceptor;
import com.hmdp.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMVCConfiguration implements WebMvcConfigurer {
    @Autowired
    private ExpireInterceptor expireInterceptor;
    @Autowired
    private LoginInterceptor loginInterceptor;

    /**
     * 注册自定义拦截器
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
            registry.addInterceptor(expireInterceptor)
                    .addPathPatterns("/**").order(0);

            registry.addInterceptor(loginInterceptor)
                    .excludePathPatterns("/user/login",
                            "/user/code",
                            "/blog/hot",
                            "/shop-type/**",
                            "/shop/**",
                            "/voucher/**",
                            "/upload/**").order(1);


    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/images/**") // 访问路径前缀
                .addResourceLocations("file:C:/Users/Asus/Pictures/Saved Pictures/"); // 本地文件夹路径
    }
}
